package com.yfbao.horizon.docker.common;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 数据库操作封装
 */
@Slf4j
public class DaoUtil {


    public static<T> List<T> selectByIds(BaseMapper<T> dao, List<Long> ids){
        if(ids ==null || ids.isEmpty()){
            return new ArrayList<>();
        }

        List<List<Long>> partition = ListUtils.partition(ids, 200);
        List<T> result = new ArrayList<>();
        for (List<Long> part : partition) {
            List<T> ts = dao.selectBatchIds(part);
//            return baseEntities;
            result.addAll(ts);
        }
        return result;
    }
}
